<template>

  <view class="content">
    <view class="information">
      <u--form labelPosition="left">
        <u-form-item label="参会姓名" prop="name" labelWidth="85" borderBottom>
          <u--input v-model="userInfo.name" placeholder="请输入参会姓名" border="none"></u--input>
        </u-form-item>
        <u-form-item label="身份证号" prop="card" labelWidth="85" borderBottom>
          <u--input v-model="userInfo.card" maxlength="18" placeholder="请输入身份证号" border="none"></u--input>
        </u-form-item>
        <u-form-item label="单位名称" prop="unit" labelWidth="85" borderBottom>
          <u--input v-model="userInfo.unit" placeholder="请输入单位名称" border="none"></u--input>
        </u-form-item>
        <u-form-item label="信用代码" prop="credit" labelWidth="85" borderBottom>
          <u--input v-model="userInfo.credit" placeholder="请输入单位统一信用代码" border="none"></u--input>
        </u-form-item>
        <u-form-item label="接收邮箱" prop="mailbox" labelWidth="85" borderBottom>

          <u--input v-model="userInfo.mailbox" placeholder="请输入接收邮箱" border="none"></u--input>

        </u-form-item>
      </u--form>

      <view class="submit" @click="submit">提交信息</view>
    </view>

  </view>

</template>

<script>
import {
  invoice, detail
} from '../../api/user'

export default {
  data() {
    return {
      userList: {},
      userInfo: {
        name: '',
        card: '',
        unit: '',
        credit: '',
        mailbox: '',
      },
      uuid: '',
      title: '请选择你的参会身份',

      show: false
    };
  },
  onLoad(options) {
    this.uuid = options.id

    this.weight(options.id)
  },
  methods: {
    Identity() {
      console.log(1111);
      this.show = true
    },

    async weight(e) {
      await detail({ order_id: e }).then(res => {
        console.log(res);
        this.userInfo.name = res.data[0].username
        this.userInfo.card = res.data[0].idcard
        this.userInfo.unit = res.data[0].unitname
      })
    },

    submit() {
      var reg = /^1[3|4|5|6|7|8|9][0-9]{9}$/;

      var idCard = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;



      if (this.userInfo.name == '') {
        uni.showToast({
          title: '请输入参会姓名',
          icon: 'none'
        })
      } else if (this.userInfo.card == '') {
        uni.showToast({
          title: '请输入身份证号',
          icon: 'none'
        })
      } else if (!idCard.test(this.userInfo.card)) {
        uni.showToast({
          title: '请输入正确的身份证号',
          icon: 'none'
        })
      } else if (this.userInfo.unit == '') {
        uni.showToast({
          title: '请输入企业单位名称',
          icon: 'none'
        })
      } else if (this.userInfo.credit == '') {
        uni.showToast({
          title: '企业统一信用代码不能为空',
          icon: 'none'
        })
      } else if (this.userInfo.mailbox == '') {
        uni.showToast({
          title: '请输入正确的收件邮箱',
          icon: 'none'
        })
      } else {
        console.log(111);

        this.submitAdd()
      }
    },

    async submitAdd() {
      await invoice({
        username: this.userInfo.name,
        idcard: this.userInfo.card,
        unitname: this.userInfo.unit,
        ucode: this.userInfo.credit,
        mailbox: this.userInfo.mailbox,
        order_id: this.uuid
      }).then(res => {
        if (res.status == 200) {
          uni.showToast({
            title: res.msg,
            icon: 'none'
          })
          this.userInfo = {}
          setTimeout(function () {
            uni.reLaunch({
              url: '/pages/index/index'
            });
          }, 1500);

        } else {
          uni.showToast({
            title: res.msg,
            icon: 'error'
          })
        }
      })
    }
  }
}
</script>
<style>
page {
  background: #f2f2f2;
}
</style>
<style lang="scss" scoped>
.content {
  .information {
    margin: 20rpx;
    padding: 25rpx;
    opacity: 1;
    border-radius: 9.31px;
    background: #ffffff;
    box-shadow: inset 1px 1px 0px #ffffff;
    backdrop-filter: blur(40px);
  }

  .submit {
    width: 186px;
    height: 40px;
    text-align: center;
    line-height: 40px;
    opacity: 1;
    border-radius: 1000px;
    background: linear-gradient(141.96deg, #d269ff 0%, #7d63ff 100%);
    margin: 50rpx auto;

    color: #ffffff;
  }
}
</style>